/* $Id: ContestUserScoreEntry.java 134 2011-08-27 16:48:38Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.datatypes.scores;

import javax.cache.Cache;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import alt.djudge.frontend.server.models.CacheModel;


@PersistenceCapable(detachable="true")
@Inheritance(customStrategy = "complete-table")
public class ContestUserScoreEntry extends AbstractScoreEntry implements UserScoreInterface, ContestScoreInterface
{
	private static final long serialVersionUID = 1L;	
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	
	@Override
	public Long getId()
	{
		return id;
	}
	
	@Override
	public void setId(Long id)
	{
		this.id = id;
	}
	
	@Persistent
	protected Long userId;
	
	@Persistent
	protected Long contestId;
	
	public void setContestId(Long contestId)
	{
		this.contestId = contestId;
	}

	public Long getContestId()
	{
		return contestId;
	}

	public ContestUserScoreEntry()
	{
		// TODO Auto-generated constructor stub
	}
	
	public ContestUserScoreEntry(Long contestId, Long userId)
	{
		this.contestId = contestId;
		this.userId = userId;
	}
	
	@Override
	public Long getUserId()
	{
		return userId;
	}

	@Override
	public void setUserId(Long userId)
	{
		this.userId = userId;
	}

	@Override
	public void clearCacheCustom()
	{
		Cache cache = CacheModel.getStaticCache();
		String keyContestUser = CacheModel.getContestUserScoreEntryKey(contestId, userId);
		cache.remove(keyContestUser);
		String keyContest = CacheModel.getContestScoreEntryKey(contestId);
		cache.remove(keyContest);
	}
}
